package org.tooyoung.fourone.live.models;

import android.util.Log;

import org.tooyoung.fourone.live.clients.networkTool;

import java.util.List;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;
import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/11/9.
 */

public class CPIgetData{
    private static List<Room> list;
    public  static void getListData()
    {

        Retrofit.Builder builder = new Retrofit.Builder();
        builder.baseUrl("http://api.fenbei.com/");
        Retrofit retrofit = builder.addConverterFactory(ScalarsConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
                .build();
        networkTool tool = retrofit.create(networkTool.class);
        Observable<RoomData> observable = tool.getRoomData(2, 1, 100000009, 1);
        observable.observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<RoomData>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d("Cpi", "onError: "+"网络访问失败");
                    }

                    @Override
                    public void onNext(RoomData roomData) {
                        if (roomData != null) {
                            List<Room> rooms = roomData.getData().getRooms();
                            list=rooms;
                        }
                    }
                });
    }
    public  static List<Room> getList()
    {
        getListData();
        if (list != null) {
            return list;
        }
        else
        {
            return  null;
        }
    }


}
